package logic

import (
	"context"
	"errors"
	"gorm.io/gorm"
	"user_srv/model/mysql"

	"user_srv/internal/svc"
	"user_srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetUserRealNameLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetUserRealNameLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserRealNameLogic {
	return &GetUserRealNameLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GetUserRealNameLogic) GetUserRealName(in *user.GetUserInfoByRealNameRequest) (*user.GetUserInfoByRealNameResponse, error) {
	// todo: add your logic here and delete this line
	ur := mysql.UserRealName{
		UserId: uint(in.UserId),
	}
	err := ur.GetUserRealNameByUserId()
	//排除这个错误 errors.Is(err, gorm.ErrRecordNotFound)
	if err != nil && errors.Is(err, gorm.ErrRecordNotFound) {
		return nil, err
	}
	return &user.GetUserInfoByRealNameResponse{RealName: ur.RealName,
		IdCard: ur.IdCard}, nil
}
